<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: order_details_wish_list.php 403 2014-01-18 16:07:03Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 403 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2014-01-18 16:07:03 +0000 (Sat, 18 Jan 2014) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */
require_once (DIR_FS_INC.'inc.check_stock.php');
require_once (DIR_FS_INC.'inc.get_clean_id.php');
require_once (DIR_FS_INC.'inc.get_product_id.php');
require_once (DIR_FS_INC.'inc.get_product_link.php');
require_once (DIR_FS_INC.'inc.decode_urlsearch.php');
require_once (DIR_FS_INC.'inc.parse_product_options.php');

$module_smarty = new Smarty;
$module_smarty->assign('tpl_path','templates/'.CURRENT_TEMPLATE.'/');

$module_content = array();
$any_out_of_stock = '';
$mark_stock = '';

for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
	if (STOCK_CHECK == 'true') {
		$mark_stock= check_stock($products[$i]['id'], $products[$i]['quantity']);
    if ($mark_stock) 
			$_SESSION['any_out_of_stock'] = 1;
	}
	
	$attributes_exist = ( (isset($products[$i]['attributes']) && count($products[$i]['attributes']) > 0) ? true : false);
	$options_exist = ( (isset($products[$i]['options']) && count($products[$i]['options']) > 0) ? true : false);

	$p_price = $products[$i][($attributes_exist||$options_exist ? 'price' : 'single_price')];
	$p_price = $price->format( $p_price, true );
	$parameter_link = '';
	$product_link = href_link(FILENAME_PRODUCT_INFO, get_all_get_params().'products_id='.get_product_id($products[$i]['id']));
	$form_options = array();

	if ($products[$i]['id']!=get_product_id($products[$i]['id'])) {
		$parameter_link = decode_urlsearch(substr($products[$i]['id'], strlen(get_product_id($products[$i]['id']))));
		$product_link = get_product_link(get_product_id($products[$i]['id']), 'konfigurator').'?p='.$parameter_link;
		$_form_options = parse_product_options($products[$i]['id']);
		foreach($_form_options as $k => $v)
			if (trim($v) != '') $form_options[] = draw_hidden_field($k, $v);
		$form_options[] = draw_hidden_field('KONFIGURATOR', 'enable');
	}

	$module_content[$i] = array(
		'FORM' => draw_form('wish_list_form', href_link(FILENAME_WISH_LIST, get_all_get_params(array('action')).'action=add_product'))
							.draw_hidden_field('products_id', get_product_id($products[$i]['id']))
							.draw_hidden_field('products_key', $products[$i]['id'])
							.draw_hidden_field('cart_quantity', 1)
							.implode('', $form_options),
		'PRODUCTS_NAME' => $products[$i]['name'].$mark_stock,
		'PRODUCTS_ID' => $products[$i]['id'],
		'PRODUCTS_ID_CLEAN' => get_clean_id($products[$i]['id']),
		'PRODUCTS_QTY' => draw_input_field('cart_quantity', $products[$i]['quantity'], 'size="2" class="products_qty"'),
		'PRODUCTS_MODEL' => $products[$i]['model'],
		'PRODUCTS_DESCRIPTION' => $products[$i]['desc'],
		'PRODUCTS_NAME_SUFFIX' => $products[$i]['name_suffix'],
		'PRODUCTS_TAX' => number_format($products[$i]['tax'], TAX_DECIMAL_PLACES),
		'PRODUCTS_IMAGE' => $products[$i]['image'],
		'PRODUCTS_VPE' => $products[$i]['vpe'],
		'PRODUCTS_WEIGHT' => $products[$i]['weight'],
		'IMAGE_ALT' => $products[$i]['name'],
		'PRODUCTS_LINK' => $product_link,
		'PRODUCTS_SINGLE_PRICE' => $price->format($products[$i]['single_price'], true),
		'PRODUCTS_PRICE' => $p_price,
		'PRODUCTS_PLUS' => href_link(FILENAME_WISH_LIST, 'wl_plus='.$products[$i]['id']),
		'PRODUCTS_MINUS' => href_link(FILENAME_WISH_LIST, 'wl_minus='.$products[$i]['id']),
		'PRODUCTS_DELETE' => href_link(FILENAME_WISH_LIST, 'wl_delete='.$products[$i]['id']),
		'ATTRIBUTES' => '',
		'OPTIONS' => '',
		'BUY_NOW' => image_submit('button_buy_now.gif', TEXT_NOW)
	);

	if ($options_exist) {
		if ( ($konfigurator = $_SESSION['cart']->use_konfigurator(true, get_prid($products[$i]['id']))) !== false ) {
			$module_content[$i]['OPTIONS'] = array(
				'DESCRIPTION' => $konfigurator->get_description($products[$i]['options'])
			);
		}
	}

    if ($attributes_exist == 1) {
	      reset($products[$i]['attributes']);

      while (list($option, $value) = each($products[$i]['attributes'])) {

          if (ATTRIBUTE_STOCK_CHECK == 'true' && STOCK_CHECK == 'true') {
            $attribute_stock_check = check_stock_attributes($products[$i][$option]['products_attributes_id'], $products[$i]['quantity']);
            if ($attribute_stock_check) $_SESSION['any_out_of_stock']=1;
          }

      $module_content[$i]['ATTRIBUTES'][]=array(
      			'ID' =>$products[$i][$option]['products_attributes_id'],
      			'MODEL'=>$products[$i][$option]['products_options_model'],
      			'NAME' => $products[$i][$option]['products_options_name'],
      			'PRICE' => ($products[$i][$option]['products_options_name'] != 'Downloads')?$price->format($products[$i][$option]['options_values_price'] * $products[$i]['quantity'],true):'',
				'PREFIX' =>  ($products[$i][$option]['products_options_name'] != 'Downloads')?$products[$i][$option]['price_prefix']:'',
      			'VALUE_NAME' => $products[$i][$option]['products_options_values_name'].$attribute_stock_check);
		}
    }
}

$total_content='';
if($_SESSION['customers_status']['customers_status_ot_discount_flag'] == '1' && $_SESSION['customers_status']['customers_status_ot_discount'] != '0.00') {
	$discount = recalculate_price($_SESSION['wish_list']->show_total(), $_SESSION['customers_status']['customers_status_ot_discount']);
    $total_content= $_SESSION['customers_status']['customers_status_ot_discount'].'% '.SUB_TITLE_OT_DISCOUNT.' -'.format_price($discount, $price_special=1, $calculate_currencies = false) .'<br />';
}

if($_SESSION['customers_status']['customers_status_show_price'] == '1')
	$total_content.= $price->format($_SESSION['wish_list']->show_total(),true);
else
	$total_content.= TEXT_INFO_SHOW_PRICE_NO;

if($customer_status_value['customers_status_ot_discount'] != 0)
	$total_content.= TEXT_CART_OT_DISCOUNT.$customer_status_value['customers_status_ot_discount'].'%';

if($_SESSION['customers_status']['customers_status_show_price'] == '1') {
	if(sizeof($products) == 1)
		$info_text = sprintf(HEAD_INFO_TXT,sizeof($products)).$total_content;
	else
		$info_text = sprintf(HEAD_INFO_TXT_MORE,sizeof($products)).$total_content;
}
$module_smarty->assign('HEAD_INFO', $info_text);
$module_smarty->assign('language', $_SESSION['language']);
$module_smarty->assign('module_content',$module_content);
$module_smarty->caching = false;
$module = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/order_details_wish_list.html');
$smarty->assign('MODULE_order_details',$module);
?>